import { Vector3, world, Player, DimensionLocation } from "@minecraft/server";

export function get_players_from_area(
  loc: DimensionLocation,
  vol: Vector3,
  tags?: string[]
) {
  return loc.dimension.getPlayers({
    location: loc,
    volume: vol,
    excludeTags: tags,
  });
}

export function get_players_from_radius(
  loc: DimensionLocation,
  radius: number,
  tags?: string[]
) {
  return loc.dimension.getPlayers({
    location: loc,
    maxDistance: radius,
    excludeTags: tags,
  });
}

export function get_player_by_name(player_name: string): Player | undefined {
  return world.getPlayers({ name: player_name }).at(0);
}

export function get_valid_players(players: Player[]) {
  return players.map((player) => {
    if (player.isValid) {
      return player;
    }
  });
}
